package edu.friday.common.base;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import java.io.Serializable;
import java.util.Date;

@MappedSuperclass
@Getter
@Setter
@RequiredArgsConstructor
@AllArgsConstructor
public class BaseModel implements Serializable {

    private static final long serialVersionUID = 1L;

    private String createBy;
    @Column(updatable = false)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm;ss")
    private Date createTime;
    private String updateBy;
    @Column(updatable = false)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm;ss")
    private Date updateTime;
    private String remark;

    @PrePersist
    protected void onCreate() {
        createTime = new Date();
    }

    @PreUpdate
    protected void onUpdate() {
        updateTime = new Date();
    }
}
